package com.qf.day01boot02mp.controller;

import com.qf.day01boot02mp.entity.UserEntity;
import com.qf.day01boot02mp.service.UserService;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public List<UserEntity> list() {
        // 1、调用业务层获取数据
        List<UserEntity> list = userService.list(); // list方法是MP中的

        // 2.返回集合
        return list;
    }

    /**
     * 添加用户
     *
     * @return
     */
    @PostMapping("/save")
    public String save(@RequestBody UserEntity userEntity) {
        boolean save = userService.save(userEntity);
        return "save" + save;
    }

    @GetMapping("/delete/{id}") // restFul风格的请求
    public String delete(@PathVariable Integer id) {
        boolean b = userService.removeById(id);
        return "delete:" + b;
    }

}
